package com.treasure.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.treasure.infrastructure.model.po.AiRobot;
import com.treasure.infrastructure.repository.dao.mapper.AiRobotMapper;
import com.treasure.web.service.IAiRobotService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sunhongmin
 * @since 2023-11-12
 */
@Service
public class AiRobotServiceImpl extends ServiceImpl<AiRobotMapper, AiRobot> implements IAiRobotService {

    @Override
    public Integer getCorpDefaultRobotId(String corpId) {
        if (StringUtils.isNotBlank(corpId) && !Objects.equals(corpId, "system")) {
            QueryWrapper<AiRobot> robotQuery = new QueryWrapper<>();
            robotQuery.lambda()
                    .eq(AiRobot::getCorpId, corpId);
            List<AiRobot> aiRobots = list(robotQuery);
            if (CollectionUtils.isNotEmpty(aiRobots) && aiRobots.stream().findFirst().isPresent()) {
                AiRobot findFirst = aiRobots.stream().findFirst().get();
                return findFirst.getId().intValue();
            }

        }
        return -1;
    }
}
